package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-17
 * Time: 19:08
 */
public class ThreadDemo2 {
    //currentThread是获取当前线程实例的方法
    //isInterrupted是t对象自带的一个标志位
    //interrupt方法就是设置标志位为true
    public static void main(String[] args) {
        Thread t=new Thread(()->{
           while(!Thread.currentThread().isInterrupted()){
               System.out.println("hello   t");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                  e.printStackTrace();
                  break;
               }

           }
        });
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
           e.printStackTrace();
        }
            t.interrupt();
    }
}
